package com.apestech.framework.run.core;

import java.util.Date;

import com.apestech.framework.run.callback.ThreadCallBackHandler;

public class SingleThread implements Runnable{
	
	private ThreadCallBackHandler callBackHandler;
	private long costTime;
	private String threadName;
	private String errorMsg="";
	private Date runTime;
	
	public SingleThread(String threadName, ThreadCallBackHandler callBackHandler){
		this.callBackHandler=callBackHandler;
		this.threadName=threadName;
	}
	
	public ThreadCallBackHandler getCallBack(){
		return this.callBackHandler;
	}

	@Override
	public void run() {
		this.runTime=new Date();
		long startTime=System.currentTimeMillis();
		try {
			this.callBackHandler.run();
		} catch (Exception e) {
			this.errorMsg=e.getMessage();
		}
		long endTime=System.currentTimeMillis();
		this.costTime=endTime-startTime;
	}
	
	public String getName(){
		return threadName;
	}

	public String getErrorMsg() {
		return errorMsg;
	}
	
	public long getCostTime(){
		return this.costTime;
	}

	public String getThreadName() {
		return threadName;
	}

	public Date getRunTime() {
		return runTime;
	}	

}
